/*
 * Presentacion.java
 *
 * Created on 11 de febrero de 2005, 08:44 AM
 */

package administrador;

import java.sql.ResultSet;
import javax.swing.ImageIcon;

/**
 *
 * @author  User
 */
public class Presentacion extends javax.swing.JPanel {
AdministradorView aviewer;
    /**
     * Creates new form Presentacion Icon
     */
    public Presentacion(AdministradorView aviewer) {
        this.aviewer=aviewer;
        initComponents();
        cargarBotones();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        bt_1 = new javax.swing.JButton();
        bt_2 = new javax.swing.JButton();
        bt_3 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(204, 204, 255));

        jPanel1.setBackground(new java.awt.Color(153, 153, 153));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Deudas Pendientes:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 1, 14), new java.awt.Color(255, 255, 255))); // NOI18N
        jPanel1.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Estado de Deudas x Cobrar:");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(70, 50, 220, 30);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Estado de Deudas x Pagar:");
        jPanel1.add(jLabel5);
        jLabel5.setBounds(70, 20, 210, 30);

        bt_1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/administrador/resources/imagenes/quitaDet.png"))); // NOI18N
        bt_1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_1ActionPerformed(evt);
            }
        });
        jPanel1.add(bt_1);
        bt_1.setBounds(10, 50, 50, 30);

        bt_2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/administrador/resources/imagenes/entra.png"))); // NOI18N
        bt_2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_2ActionPerformed(evt);
            }
        });
        jPanel1.add(bt_2);
        bt_2.setBounds(10, 20, 50, 30);

        bt_3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/administrador/resources/imagenes/entra.png"))); // NOI18N
        bt_3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_3ActionPerformed(evt);
            }
        });
        jPanel1.add(bt_3);
        bt_3.setBounds(10, 80, 50, 30);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Estado de la Autorizacion:");
        jPanel1.add(jLabel6);
        jLabel6.setBounds(70, 80, 220, 30);

        jButton2.setText("Actualiza Base Bodega");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2);
        jButton2.setBounds(10, 120, 140, 30);

        jPanel2.setBackground(new java.awt.Color(153, 153, 153));
        jPanel2.setLayout(null);

        jLabel3.setText("Desarrollado por:");
        jPanel2.add(jLabel3);
        jLabel3.setBounds(110, 20, 150, 20);

        jLabel4.setText("Ing.daniel1 Silva Palacios");
        jPanel2.add(jLabel4);
        jLabel4.setBounds(110, 40, 150, 14);

        jLabel7.setText("Ing. Jorge Morales P.");
        jPanel2.add(jLabel7);
        jLabel7.setBounds(110, 60, 150, 14);

        jLabel8.setText("danyche2005@hotmail.com");
        jPanel2.add(jLabel8);
        jLabel8.setBounds(110, 80, 150, 10);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/calendario/iconoMed.png"))); // NOI18N
        jPanel2.add(jLabel2);
        jLabel2.setBounds(10, 10, 100, 100);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap(501, Short.MAX_VALUE)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 270, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 290, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(481, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 194, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 309, Short.MAX_VALUE)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 110, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents
    public void refrescar(){
    cargarBotones();
    }
    
    
    public void cargarBotones(){
    //Pregunto el estado de las Deudas x Cobrar:
    String fecha=new java.sql.Date(System.currentTimeMillis()).toString();//Fecha Actual:    
    ResultSet resp=aviewer.c.consultarBase("SELECT * FROM cuentaspendientes where pagado like 'falta' and fecha_max<='"+fecha+"' and tipo like 'xcobrar';");
    if(aviewer.c.obtenerFilas(resp)>0){
    //Pongo que tengo deudas x Cobrar en el boton:
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(administrador.AdministradorApp.class).getContext().getResourceMap(AdminTerminal.class);
        java.net.URL imgURL = getClass().getResource("/administrador/resources/imagenes/" + "mal.png");
        ImageIcon icono1=new ImageIcon(imgURL, "todo bien");
        bt_1.setIcon(icono1);
        bt_1.updateUI();
        
    }else{
    //No existen deudas x Cobrar Atrasadas:
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(administrador.AdministradorApp.class).getContext().getResourceMap(AdminTerminal.class);
        java.net.URL imgURL = getClass().getResource("/administrador/resources/imagenes/" + "bien.png");
        ImageIcon icono1=new ImageIcon(imgURL, "todo bien");
        bt_1.setIcon(icono1);
        bt_1.updateUI();
    }
    
    //Pregunto si tengo deudas x Pagar
    resp=aviewer.c.consultarBase("SELECT * FROM cuentaspendientes where pagado like 'falta' and fecha_max<='"+fecha+"' and tipo like 'xpagar';");
    if(aviewer.c.obtenerFilas(resp)>0){
    //Pongo que tengo deudas x Cobrar en el boton:
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(administrador.AdministradorApp.class).getContext().getResourceMap(AdminTerminal.class);
        java.net.URL imgURL = getClass().getResource("/administrador/resources/imagenes/" + "mal.png");
        ImageIcon icono1=new ImageIcon(imgURL, "todo bien");
        bt_2.setIcon(icono1);
        bt_2.updateUI();
    }else{
    //No existen Deudas x Pagar Atrasadas:
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(administrador.AdministradorApp.class).getContext().getResourceMap(AdminTerminal.class);
        java.net.URL imgURL = getClass().getResource("/administrador/resources/imagenes/" + "bien.png");
        ImageIcon icono1=new ImageIcon(imgURL, "todo bien");
        bt_2.setIcon(icono1);
        bt_2.updateUI();
    }
    
    //Pongo si la Autorizacion caduco o no:
    if(autorizacionCaduca()){
        //La Autorizacion esta caducada:
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(administrador.AdministradorApp.class).getContext().getResourceMap(AdminTerminal.class);
        java.net.URL imgURL = getClass().getResource("/administrador/resources/imagenes/" + "mal.png");
        ImageIcon icono1=new ImageIcon(imgURL, "todo bien");
        bt_3.setIcon(icono1);
        bt_3.updateUI();
    }else{
        //La Autorizacion no ha Caducado:
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(administrador.AdministradorApp.class).getContext().getResourceMap(AdminTerminal.class);
        java.net.URL imgURL = getClass().getResource("/administrador/resources/imagenes/" + "bien.png");
        ImageIcon icono1=new ImageIcon(imgURL, "todo bien");
        bt_3.setIcon(icono1);
        bt_3.updateUI();
    
    }
    
    
    }
    
    
    public boolean autorizacionCaduca(){
    boolean resultado=false;    
        int existe=0;
        String fecha=new java.sql.Date(System.currentTimeMillis()).toString();
        ResultSet resp=aviewer.c.consultarBase("SELECT * FROM autorizacion where '"+fecha+"'<=fecha_fin;");
        existe=aviewer.c.obtenerFilas(resp);
        if (existe==0){
        resultado=true;
        }
    return resultado;    
    }
    
private void bt_2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_2ActionPerformed
// TODO add your handling code here:
    //Almaceno la ventana en el vector de ventanas activas:
        aviewer.adminDeudas();
}//GEN-LAST:event_bt_2ActionPerformed

private void bt_1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_1ActionPerformed
// TODO add your handling code here:
    //Almaceno la ventana en el vector de ventanas activas:
        aviewer.adminDeudas();
}//GEN-LAST:event_bt_1ActionPerformed

private void bt_3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_3ActionPerformed
// TODO add your handling code here:
        modAutorizacion mau=new modAutorizacion(aviewer.c,aviewer.user,this);
}//GEN-LAST:event_bt_3ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    System.out.println("***Realiza la Actualizacion Base Bodega de la BASE INTERNET***");
    PanelActualizacion pa=new PanelActualizacion();
    ProActualizaWebDB paw=new ProActualizaWebDB(aviewer.c,pa,this.aviewer.bodega);
    paw.start();


}//GEN-LAST:event_jButton2ActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_1;
    private javax.swing.JButton bt_2;
    private javax.swing.JButton bt_3;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
    
}
